package functii.elementare;

import operatori.Produs;
import functii.Functie;

public class Putere extends Functie{
    public static double calcul(double aux1){
        return Math.pow(aux1, 2.0);
    }

    public double calcul(){
        if(fStang == null)
            System.exit(1);
        return calcul(fStang.calcul());
    }

    public String derivare(){
        if(fStang == null)
            System.exit(1);
        return Produs.concatTermens("2.0",fStang.toString());
    }

    public double calculDerivata(){
    	if(fStang==null || fDrept==null)
			System.exit(1);
		return Produs.Calcul(2.0, calcul(fStang.calculDerivata()));
    }
    public String toString(){
        if(fStang == null)
            System.exit(1);
        return concatTermeni(fStang.toString());
    }

    public String concatTermeni(String aux1){
        String aux;
        int nrP;

        nrP = aux1.charAt(0) == '(' ? 0 : 2;

        aux = "^2";
        if(nrP != 0) aux += "(";
        aux += aux1;
        if(nrP != 0) aux += ")";

        return aux;
    }

	public static String concatTermens(String aux1) {
		String aux;
        int nrP;

        nrP = aux1.charAt(0) == '(' ? 0 : 2;

        aux = "^2";
        if(nrP != 0) aux += "(";
        aux += aux1;
        if(nrP != 0) aux += ")";

        return aux;
	}
}
